﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.DirectoryServices.AccountManagement;
using System.DirectoryServices;
using System.Configuration;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            UpdateCaptchaText();
        }
        //Connector Con = Helper.GetConnector(ConfigurationManager.AppSettings["ConnectorType"]);
    }
    private void UpdateCaptchaText()
    {
        // txtCaptchaText.Text = string.Empty;
        //  lblStatus.Visible = false;
        //Store the captcha text in session to validate
        Session["Captcha"] = Guid.NewGuid().ToString().Substring(0, 6);
    }



    protected void ChangePassButton_Click(object sender, EventArgs e)
    {
        bool success = false;
        if (Session["Captcha"] != null)
        {
            //Match captcha text entered by user and the one stored in session
            if (Convert.ToString(Session["Captcha"]) == txtCaptchaText.Text.Trim())
            {
                success = true;
            }
        }

        lblStatus.Visible = true;
        if (!success)
        {
            lblStatus.Text = "Введите код с картинки";
            lblStatus.ForeColor = System.Drawing.Color.Red;
            return;
        }

        //logic here

        Connector Conn = Helper.GetConnector(ConfigurationManager.AppSettings["ConnectorType"]);
        //form data from page
        //this is just example
        CatalogProperty[] prop = new CatalogProperty[3];
        prop[0] = new CatalogProperty { Property = "FirstName", Value = "Алексей Сергеевич" };
        prop[1] = new CatalogProperty { Property = "LastName", Value = "Абаев" };
        prop[2] = new CatalogProperty { Property = "department", Value = "327284" };

        Conn.ChangePassword(Conn.FindUser(prop, true), "Flbk6057111");

        Success.InnerText = "Вот ваш новый пароль:" + "Flbk6057111";
        parent_popup.Visible = true;
        Success.Visible = true;
    }
}